package org.example.controller;

import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.jms.Destination;

/**
 * @author GuoChunbo
 * @create 2021-03-08 10:35
 * @Description: 类的描述
 */
@RestController
public class MsgController {

    @Autowired
    JmsMessagingTemplate jmsMessagingTemplate;

    @PostMapping("send")
    public void send(String msg) {
        //发送topic类型的
        Destination destination = new ActiveMQTopic("news_msg");
        jmsMessagingTemplate.convertAndSend(destination, msg);
        System.out.println("发送一条消息");
    }
}
